import { http } from "@/utils/http";

export type ResultType = ReplaceTargetType<any[]>;

export const getList = (current, size, params) => {
  return http.request<any>({
    url: "/cupUserApi/page",
    method: "get",
    params: {
      ...params,
      current,
      size,
    },
  });
};

export const getAllUserList = (params) => {
  return http.request<any>({
    url: "/cupUserApi/list",
    method: "get",
    params: params,
  });
};

export const add = (row) => {
  return http.request<any>({
    url: "/cupUserApi/submit",
    method: "post",
    data: row,
  });
};

export const remove = (ids) => {
  return http.request<any>({
    url: "/cupUserApi/remove",
    method: "post",
    params: {
      ids,
    },
  });
};

export const update = (row) => {
  return http.request<any>({
    url: "/cupUserApi/update",
    method: "post",
    data: row,
  });
};

export const grant = (userIds, roleIds) => {
  return http.request({
    url: "/cupUserApi/grant",
    method: "post",
    params: {
      userIds,
      roleIds,
    },
  });
};

export const getUser = (id) => {
  return http.request<any>({
    url: "/cupUserApi/detail",
    method: "get",
    params: {
      id,
    },
  });
};

export const getUserInfo = () => {
  return http.request({
    url: "/cupUserApi/info",
    method: "get",
  });
};

export const downloadExcel = () => {
  return http.request({
    url: "/cupUserApi/export-user",
    method: "get",
  });
};

export const downloadExcelTemp = () => {
  return http.request<any>({
    url: "/cupUserApi/export-template",
    method: "get",
    responseType: "blob",
  });
};

export const resetPassword = (userIds) => {
  return http.request({
    url: "/cupUserApi/reset-password",
    method: "post",
    params: {
      userIds,
    },
  });
};

export const updatePassword = (oldPassword, newPassword, newPassword1) => {
  return http.request({
    url: "/cupUserApi/update-password",
    method: "post",
    params: {
      oldPassword,
      newPassword,
      newPassword1,
    },
  });
};

export const getDeptListApi = (params) => {
  return http.request<any>({
    url: "/kg-service/kg/v1.0/user/list-by-attr",
    method: "post",
    params: {},
    data: params,
  });
};
